import { DeleteDto, IndexDto, ShowDto } from '@libs/common/dto';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsEnum, IsInt, IsNotEmpty, IsNumber, IsString } from 'class-validator';
import { FindOperator } from 'typeorm';

import { OrderResult } from '@/constant.enum';

import { Order } from '../entities/order.entity';

export class IndexOrderDto extends IndexDto<Order> {}

export class ShowOrderDto extends ShowDto {}

export class DeleteOrderDto extends DeleteDto {}

export class CreateOrderDto {
  @ApiProperty({ description: '用户 id' })
  @IsNotEmpty({ message: '用户 id 不能为空' })
  userId: string;

  @ApiProperty({ description: '用户名称' })
  @IsNotEmpty({ message: '用户名称不能为空' })
  userName: string;

  @ApiProperty({ description: '订单号' })
  @IsNotEmpty({ message: '订单号不能为空' })
  orderNo: string;

  @ApiProperty({ description: '订单状态' })
  @IsEnum(OrderResult, { message: '订单状态不正确' })
  @IsNotEmpty({ message: '订单状态不能为空' })
  status: OrderResult;

  @ApiProperty({ description: '流水号' })
  @IsNotEmpty({ message: '流水号不能为空' })
  deviceTransNo: string;

  @ApiProperty({ description: '货道编号' })
  @IsNotEmpty({ message: '货道编号不能为空' })
  deviceRoadNo: string;

  @ApiProperty({ description: '货道ID' })
  @IsNotEmpty({ message: '货道ID不能为空' })
  deviceRoadId: string;

  @ApiProperty({ description: '订单总价' })
  @IsNotEmpty({ message: '订单总价不能为空' })
  @IsInt({ message: '订单总价不正确' })
  totalPrice: number;

  @ApiProperty({ description: '商品ID' })
  @IsNotEmpty({ message: '商品ID不能为空' })
  productId: string;

  @ApiProperty({ description: '商品价格' })
  @IsNotEmpty({ message: '商品价格不能为空' })
  @IsInt({ message: '商品价格不正确' })
  productPrice: number;

  @ApiProperty({ description: '商品名称' })
  @IsNotEmpty({ message: '商品名称不能为空' })
  @IsString({ message: '商品名称不正确' })
  productName: string;

  @ApiProperty({ description: '商品数量' })
  @IsNotEmpty({ message: '商品数量不能为空' })
  @IsNumber({}, { message: '商品数量不正确' })
  productNumber: number;

  @ApiProperty({ description: '商品图片' })
  productImage?: string;
}

export class UpdateOrderDto extends PartialType(CreateOrderDto) {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;
}

export class SwitchOrderDto {}

export class ImportOrderDto {}

export class ExportOrderDto {}

export class RefundOrderDto {
  @ApiProperty({ description: '订单号' })
  @IsNotEmpty({ message: '订单号不能为空' })
  orderNo: string;
}

export class FindOrderDto {
  createdAt?: Date | FindOperator<any>;
  userId?: string | FindOperator<any>;
  productId?: string;

  status?: OrderResult;
}

export class CheckOrderStatusManual {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;
}
